package com.tong.embeddedvr.Mapper;

import com.tong.embeddedvr.dto.UserOutputDTO;
import com.tong.embeddedvr.entity.UserEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Map;

@Mapper
@Repository
public interface UserMapper {

    /**
     * @Description userEntity
     * @Author gcl
     * @Date 2021/2/24 13:37
     * @param: userEntity
     * @Return com.tong.embeddedvr.dto.UserOutputDTO
     */
    @Select("SELECT COUNT(*) FROM user WHERE user_username = #{userEntity.userUsername} AND user_is_delete = 0")
    public UserOutputDTO[] usernameCount(@Param("userEntity") UserEntity userEntity);

    /**
     * @Description 添加用户
     * @Author gcl
     * @Date 2021/2/24 13:27
     * @param: userEntity
     * @Return void
     */
    @Insert("INSERT INTO user(user_nickname,user_username,user_password,user_telephone,user_email,user_is_delete) VALUES(#{userEntity.userNickname},#{userEntity.userUsername},MD5(#{userEntity.userPassword}),#{userEntity.userTelephone},#{userEntity.userEmail},0)")
    public void addUser(@Param("userEntity")UserEntity userEntity);

    /**
     * @Description 根据用户名和密码判断用户是否可以登录
     * @Author gcl
     * @Date 2021/2/24 13:29
     * @param: userEntity
     * @Return com.tong.embeddedvr.dto.UserOutputDTO
     */
    @Select("SELECT * FROM user WHERE user_username = #{userEntity.userUsername} AND user_password = MD5(#{userEntity.userPassword}) AND user_is_delete = 0")
    public UserOutputDTO getUserByUsernameAndPassword(@Param("userEntity")UserEntity userEntity);
    
    /**
     * @Description 判断手机号是否已注册或者根据手机号登录
     * @Author gcl
     * @Date 2021/2/24 14:32
     * @param: userEntity
     * @Return com.tong.embeddedvr.dto.UserOutputDTO[]
     */
    @Select("SELECT * FROM user WHERE user_telephone = #{userEntity.userTelephone} AND user_is_delete = 0")
    public UserOutputDTO[] getUserByTelephone(@Param("userEntity")UserEntity userEntity);

    /**
     * @Description 获取用户信息
     * @Author gcl
     * @Date 2021/2/24 13:34
     * @param: userEntity
     * @Return com.tong.embeddedvr.dto.UserOutputDTO
     */
    @Select("SELECT * FROM `user` WHERE user_id = #{userEntity.userId} AND user_is_delete = 0")
    public UserOutputDTO getUserById(@Param("userEntity")UserEntity userEntity);


    /**
     * @Description 更新用户信息
     * @Author gcl
     * @Date 2021/2/24 13:33
     * @param: userEntity
     * @Return void
     */
    public void updateInformation(@Param("userEntity")UserEntity userEntity);

}
